package com.it.tools;


import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 羡羡
 * 日期转换器  1、年月日   2、..../../..   3、xxxx-xx-xx
 */
public class MyDateConverter implements Converter<String, Date> {

    @Override
    public Date convert(String source) {
        SimpleDateFormat sdf=null;
        Date da=null;
        if(source.contains("年")){
            sdf=new SimpleDateFormat("yyyy年MM月dd日");
        }else if(source.contains("-")){
            sdf=new SimpleDateFormat("yyyy-MM-dd");
        }else if(source.contains("/")){
            sdf=new SimpleDateFormat("yyyy/MM/dd");
        }
        try {
            da=sdf.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return da;
    }
}
